package com.jjsj.web.controller.mall;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jjsj.common.core.controller.BaseController;
import com.jjsj.common.core.domain.AjaxResult;
import com.jjsj.mall.entity.OrderReceipt;
import com.jjsj.mall.service.IOrderReceiptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 订单发票信息Controller
 *
 * @author www.jjsjshop.com
 * @date 2022-10-10
 */
@RestController
@RequestMapping("/mall/receipt")
public class OrderReceiptController extends BaseController {
    @Autowired
    private IOrderReceiptService orderReceiptService;

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param orderReceipt 订单物流
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:receipt:index')")
    public AjaxResult getOrderReceiptPage(Page page, OrderReceipt orderReceipt) {
        return AjaxResult.success(orderReceiptService.page(page, Wrappers.query(orderReceipt)));
    }

    /**
     * 通过id查询订单物流
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id查询订单物流")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:receipt:get')")
    public AjaxResult getById(@PathVariable("id") String id) {
        return AjaxResult.success(orderReceiptService.getById(id));
    }

    /**
     * 新增订单物流
     *
     * @param orderReceipt 订单物流
     * @return R
     */
    @ApiOperation(value = "新增订单物流")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:receipt:add')")
    public AjaxResult save(@RequestBody OrderReceipt orderReceipt) {
        return AjaxResult.success(orderReceiptService.save(orderReceipt));
    }

    /**
     * 修改订单物流
     *
     * @param orderReceipt 订单物流
     * @return R
     */
    @ApiOperation(value = "修改订单物流")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:receipt:edit')")
    public AjaxResult updateById(@RequestBody OrderReceipt orderReceipt) {
        return AjaxResult.success(orderReceiptService.updateById(orderReceipt));
    }

    /**
     * 通过id删除订单物流
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id删除订单物流")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:receipt:del')")
    public AjaxResult removeById(@PathVariable String id) {
        return AjaxResult.success(orderReceiptService.removeById(id));
    }
}
